<template>
  <div>
    <!-- 列表 -->
    <!-- 
          data:数据
          row-key：一行的唯一标识
          border：加边框
           default-expand-all:默认展开所有数据
          default-expand-all：默认展开所有数据
           :tree-props="{ children: '由哪个字段来判断是否有子节点' }"
    -->

    <el-table
      :data="list"
      style="width: 100%;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="用户编号" sortable width="180"></el-table-column>
      <el-table-column prop="nickname" label="昵称" sortable width="180"></el-table-column>
      <el-table-column prop="phone" label="手机号" sortable width="180"></el-table-column>

      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1" @click="handleEdit(scope)">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleEdit(scope)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// 引入vuex中的辅助函数
import { mapActions, mapGetters } from "vuex";
import { successAlert } from "../../../utils/alert";
export default {
  data() {
    return {};
  },
  computed:{
    ...mapGetters({
      list:'vip/list'
    })
  },
  mounted(){
    // 一进页面就请
    this.reqList()
  },
  methods: {
    ...mapActions({
      reqList:'vip/reqList'
    }),
    handleEdit(scope) {
      //   console.log(scope);
      //   scope.$index 下标
      // scope.row 那条数据 item
      // 通知父组件,并且将这行的id带上
      this.$emit("willUpdate", scope.row.uid);
    },
    handleDelete(scope) {
      //   单击了删除，
      this.$confirm("您确定要删除么?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          //  开始删除
          reqmenudelete({
            id: scope.row.id
          }).then(res => {
            if (res.data.code == 200) {
              //弹成功
              successAlert(res.data.msg);
              //  重新获取list
              this.$emit("init");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>

<style>
</style>